//
//  UserModuleManager.m
//  Manager
//
//  Created by issac on 15/8/28.
//  Copyright (c) 2015年 52xiaoluo. All rights reserved.
//

#import "UserModuleManager.h"
#import "QueueLogic.h"


@implementation UserModuleManager
{
    NSMutableArray *modules;
}

static UserModuleManager* _instance = nil;

+(instancetype) shareInstance
{
    static dispatch_once_t onceToken ;
    dispatch_once(&onceToken, ^{
        _instance = [[UserModuleManager alloc] init] ;
    });
    
    return _instance ;
}

-(id) init {
    modules = [[NSMutableArray alloc]init];
    return self;
}


-(void)registerUserModule:(id<UserModule>) module {
    @synchronized(self) {
        if (module) {
            BOOL find = false;
            for (id<UserModule> m in modules) {
                if (m == module) {
                    find = true;
                    break;
                }
            }
            if (!find) {
                [modules addObject:module];
            }
        }
    }
}

-(void)userLogout {
    for (id<UserModule> m in modules) {
        dispatch_async([[QueueLogic shareInstance]getWorkQueue], ^{
            [m userLogout];
        });
    }
}

-(void)userLogin {
    for (id<UserModule> m in modules) {
        dispatch_async([[QueueLogic shareInstance]getWorkQueue], ^{
            [m userLogin];
        });
    }
}

@end
